<template>
	<view class="">
		<view class="bj">
			<!-- <image class="jj" src="https://oss.jht.jht.cash/img/20250605/ZHuLnIKu.png" mode="widthFix"></image> -->
			<view class="content">
				<view class="logon-message1">
					欢迎使用嘉会通
				</view>
				<view class="logon-message">
					<view style="margin-top: 30rpx;">
						<view class="logon-message-phone">
							<input v-model="phone" @input="inputFn"
								style="caret-color: #FF4F01; color: #333333; font-size: 28rpx;width: 100%;height: 96rpx;line-height: 96rpx"
								adjust-position="false" class="uni-input" maxlength="11" type="tel"
								placeholder="请输入手机号" />
						</view>
					</view>
					<view style="margin-top: 30rpx;">

						<view class="logon-message-phone">
							<input class="uni-input" @input="inputFnYzm"
								style=" caret-color: #FF4F01; color: #333333; font-size: 28rpx;width: 50%;height: 96rpx;line-height: 96rpx"
								adjust-position="false" v-model="smsCode" maxlength="4" type="tel"
								placeholder="请输入验证码" />
							<text class="getCode" v-if="count==60" @click="$noMultipleClicks(sendCode)">
								获取验证码
							</text>
							<text class="getCode" v-else>{{count}}秒后重试</text>
						</view>
					</view>

					<view style="margin-right: 5vw; margin-top: 34rpx;flex-direction: row;align-items: center;">

						<image class="ty-img" @click="tyBtn" v-if="tyBtnIndex==false"
							src="@/static/index/icon_nor_ty.png" mode="aspectFit"></image>
						<image v-else class="ty-img" @click="tyBtn" src="@/static/index/icon_select_ty.png"
							mode="aspectFit">
						</image>

						<text style="color: #D1D1D1;font-size: 24rpx;">我已阅读并同意</text>
						<text style=";font-size: 24rpx;" @click="xyBtn(item,index)" v-for="(item,index) in xyList">
							<text class="clor-text">《{{item.tit}}》</text>
							<text style="color: #D1D1D1;">{{index+1!=xyList.length?'与':''}}</text>

						</text>
					</view>
					<view class="logon-message-submit" @click="$noMultipleClicks(loginclick)">
						立即登录
					</view>
				</view>
				<uni-popup ref="xyPup" type="bottom" border-radius="10px 10px 0 0">

					<view class="xyPup">
						<xyswiper :xyList="xyList" :active="xyActive"></xyswiper>
					</view>
				</uni-popup>
				<uni-popup ref="backAffirm" type="center" border-radius="10px 10px 0 0">
					<view class="backAffirm-wrap">
						<view class="backAffirm-wrap-heard">
							<image src="@/static/index/icon_jb.png" mode=""></image>
							<!-- <image src="@/static/index/icon_close.png" mode=""></image> -->
						</view>
						<view class="backAffirm-wrap-des">
							您可能会错过以下权益
						</view>

						<view class="backAffirm-wrap-list">

							<view class="backAffirm-wrap-list-msg" v-for="(item,index) in backAffirmList" :key="index">
								<image class="backAffirm-wrap-list-msg-img" :src="item.url" mode=""></image>
								<view class="backAffirm-wrap-list-msg-msg">{{item.msg}}</view>
							</view>

						</view>
						<view class="backAffirm-wrap-ts">
							信息加密存储仅用于资质申请，平台承诺不会泄露您的任何信息。
						</view>

						<view class="backAffirm-wrap-btn" @click="goPage('/pagesC/list/index')">
							立即申请
						</view>
					</view>
					<view class="backAffirm-wrap-close" @click="closeBackAffirm">
						<image src="@/static/index/icon_gb.png" mode=""></image>
					</view>
				</uni-popup>

			</view>

		</view>
		<view class="nofind" v-if="false">
			<view class="nofindImg">
				<image src="@/static/index/icon_404.png" mode=""></image>
			</view>
			<view>暂未找到页面</view>

		</view>
	</view>


</template>

<script>
	import xyswiper from '@/components/xySwiper.vue'
	import {
		login,
		clickChannel,
		sendSmsCode,
		checkChannelV1,
		oldRegisterV5,
		analysis
	} from "@/api/index.js";


	import w_md5 from "@/js_sdk/zww-md5/w_md5.js"
	import {
		JSEncrypt
	} from 'jsencrypt-plus';

	export default {
		components: {
			w_md5,
			xyswiper
		},
		data() {
			return {
				backAffirmList: [{
						url: '@/static/index/icon_tag1.png',
						msg: '以匹配产品的申请机会'
					},
					{
						url: '@/static/index/icon_tag2.png',
						msg: '初审已通过，确认额度立即提现'
					},
					{
						url: '@/static/index/icon_tag3.png',
						msg: '优质信贷经理专属服务'
					}
				],
				// 防抖节流
				noClick: true,
				tyBtnIndex: false,
				xyList: [{
						tit: '注册协议',
						url: 'https://h5.jht.cash/xy/jhtzcxy.html'
					},
					{
						tit: '隐私协议',
						url: 'https://h5.jht.cash/xy/jhtyxxysdk.html'
					}

				],
				xyActive: null,
				phone: "",
				smsCode: "",
				isWeixin: false,
				isOpen: 1,
				count: 60, // 倒计时总秒数
				timer: null, // 定时器
			}

		},
		async onShow() {

			// 用户免登录
			// this.tokens = JSON.parse(localStorage.getItem('tokens'));
			// if (this.tokens) {
			// 	// copy 取得   
			// 	uni.setStorageSync('token', this.tokens);
			// 	let pppp = await oldRegisterV5()
			// 	this.goPagesList(pppp)
			// }
			// 用户免登录
			this.$ymmd({
				name: '首页',
				age: "23"
			})

		},

		async onLoad(option) {
			// 获取跳转过来的链接结束
			let queryParams = {}
			var PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
								MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC41n1LMlYKesjPaLEYjEg2R7AZ
								1lOdyjudhTvKrXEdQc9XrxtZIJZhQhmkyZquBsUrtxzRaLIraIhUWbxmaaBiqbLE
								bFWduIIcqbtnSEE2zZhBOqdnj3qa1YzEbo6bOEUB0cGWMy0yNlQBGJVMFAFIywEL
								4Diuf3ByF5Fs5Xs4YwIDAQAB
								-----END PUBLIC KEY-----`;
			var encryptContext = new JSEncrypt();
			encryptContext.setPublicKey(PUBLIC_KEY);
			var data = {
				time: new Date().getTime(),
				sign: 'zsSuzfL0f5'
			};
			data = JSON.stringify(data);
			var encryptedData = encryptContext.encryptLong(data);
			// this.init(encryptedData)
			this.phone = uni.getStorageSync('phone');
		},
		beforeDestroy() {
			if (this.timer) { // 组件销毁前清除定时器，防止内存泄漏
				clearInterval(this.timer);
			}
		},
		methods: {
			inputFn(e) {
				
				if (this.phone.length == 11) {
					this.sendCode()
				}
			},
			inputFnYzm(e) {
				if (this.smsCode.length == 4) {
					this.tyBtnIndex = true

					this.loginclick()
				}
			},
			closeBackAffirm() {
				this.$refs.backAffirm.close()
				this.$refs.surePageLj.close()

			},
			async init(encryptedData) {
				var iswx = 0
				let res = await checkChannelV1()
				// 微信浏览器条件下运行   
				if (this.isWeiXinBrowser()) {
					iswx = 1
					if (res.data.wxopen == 0) {
						this.isWeixin = true
					} else if (res.data.wxopen == 1) {
						this.isWeixin = false
					}
				} else {
					iswx = 0
				}
				if (res.data.status == 0) {
					// 404
					this.isOpen = -1
				} else {
					this.isOpen = 1
					var hostname = location.hostname

				}

				let ddd = {
					"mobile": '',
					"type": 1,
					"sign": encryptedData,
					"iswx": iswx
				}
				let res2s = await clickChannel(ddd)
			},
			// 打开协议
			xyBtn(item, index) {
				this.xyActive = index
				console.log(item, '这是啥啊')
				this.$refs.xyPup.open()
			},
			// 是否同意
			tyBtn() {
				this.tyBtnIndex = !this.tyBtnIndex
			},


			async sendCode() {

				let regex = /^1[3-9]\d{9}$/;
				if (!regex.test(this.phone)) {
					this.ts("请输入正确的手机号码")
					return;
				}
				this.$ymmdBtn("ymBtnCode", {
					name: '验证码',
					phone: this.phone
				})
				uni.showLoading({
					title: '正在发送验证码',

				});
				let timestamp1 = new Date().getTime();
				let newStr = timestamp1.toString().slice(0, -4) + timestamp1.toString().slice(-3);

				let sk = w_md5.hex_md5_32(newStr + this.phone);
				let data = {
					"mobile": this.phone,
					"sk": sk,
					"timestamp": timestamp1,
					"type": 1
				}
				let rrr = await sendSmsCode(data)
				if (rrr.code == 100000) {
					this.$ts("发送成功!")
					uni.hideLoading();
					this.startCountdown();
				}

			},
			startCountdown() {
				this.count -= 1;
				this.timer = setInterval(() => {
					if (this.count > 0) {
						this.count -= 1;
					} else {
						clearInterval(this.timer); // 清除定时器
						this.count = 60
					}
				}, 1000);
			},
			async loginclick() {
				
				
				// return;
				let regex = /^1[3-9]\d{9}$/;
				if (!regex.test(this.phone)) {
					this.ts("请输入正确的手机号码")
					return;
				} else if (this.smsCode == '') {
					this.ts("请输入验证码")
					return;
				} else if (!this.tyBtnIndex) {
					this.ts("请同意并勾选协议")
					return;
				}
				
				this.$ymmdBtn("ymBtnLogin", {
					name: '点击登录',
					phone: this.phone,
					code: this.smsCode,
				})
				
				
				
				let phoneStr = this.phone
				var that = this
				var sk = w_md5.hex_md5_32(phoneStr + "Nas1WjGRGe");
				uni.showLoading({})
				let data = {
					"mobile": phoneStr,
					"sk": sk,
					"code": this.smsCode,
				}
				let res1 = await login(data)
				uni.hideLoading()
				uni.setStorageSync('token', res1.data.userMess.token);
				uni.setStorageSync('userInfo', res1.data.userMess);
				// localStorage.setItem('tokens', JSON.stringify(res1.data.userMess.token));
				if (res1.code == 100000) {
					let data2 = {
						"mobile": phoneStr,
						"type": 2
					}
					let res2 = await clickChannel(data2)

				}
				uni.switchTab({
					url:'/pages/index/index'
				})
				return;
				this.goPagesList(res1)
			},
			goPagesList(res1) {
				let that = this
				var url = "";
				switch (res1.data.page) {
					case "form":
						url = "/pagesA/form/index"
						break;
					case "list":
						url = "/pagesC/list/index"
						break;
					case "sure1":
					case "sure2":
					case "shop":
						url = "/pagesA/form/index"
						break;
					case "form_match":
						const data = encodeURIComponent(JSON.stringify(res1.data.userinfo));
						url = `/pagesA/form/indexOld?type=1&userInfo=${data}`;
						break;
					case "end":
						url = `/pagesE/result/index`;
						break;
				}
				if (url.length > 0) {
					uni.navigateTo({
						url: url
					})
				}
			},
			ts(tit) {
				uni.showToast({
					title: tit,
					icon: 'none',
					duration: 2000
				})
			},
			goPage(url) {
				uni.navigateTo({
					url
				})
				this.$refs.backAffirm.close()
			},

		},

	}
</script>

<style lang="scss">
	.clor-text {
		color: $mian-color;
	}

	.nofind {

		margin: 300rpx auto;
		text-align: center;

		.nofindImg {
			width: 200rpx;
			height: 200rpx;
			text-align: center;
			margin: 30rpx auto;

			// line-height: 80rpx;
			image {
				width: 100%;
				height: 100%;
				vertical-align: middle;
			}
		}

	}

	.backAffirm-wrap {
		.backAffirm-wrap-list {
			.backAffirm-wrap-list-msg {
				.backAffirm-wrap-list-msg-img {
					width: 32rpx;
					height: 32rpx;

					vertical-align: center;
				}

				.backAffirm-wrap-list-msg-msg {
					font-size: 30rpx;
					margin-left: 20rpx;
				}

				display: flex;
				align-items: center;
				margin: 30rpx;
			}

			width: 80%;
			padding:4rpx 36rpx;
			margin: 0 auto;
			background: #EBF3FF;
			border-radius: 20rpx;
		}

		.backAffirm-wrap-btn {
			background: linear-gradient(90deg, #6CB0F2 0%, #3C75F2 100%);
			box-shadow: 0px 8rpx 15px 2px #B2CBEA;
			border-radius: 100rpx;
			width: 60%;
			margin: 20rpx auto auto auto;
			line-height: 80rpx;
			text-align: center;
			color: #ffffff;
			font-size: 30rpx;

		}

		.backAffirm-wrap-ts1 {
			font-size: 28rpx;
			color: #999999;
			text-align: center;
		}

		.backAffirm-wrap-ts {
			color: #999999;
			font-size: 26rpx;
			width: 80%;
			margin: 30rpx auto;
		}

		.backAffirm-wrap-price {
			display: flex;
			align-items: center;
			justify-content: center;

			.backAffirm-wrap-price-left {
				font-weight: 500;
				font-size: 48rpx;
				color: $mian-color;
			}

			.backAffirm-wrap-price-right {
				font-weight: bold;
				font-size: 100rpx;
				color: $mian-color;
			}
		}

		.backAffirm-wrap-des1 {
			color: #333;
			font-size: 30rpx;
			text-align: center;
			padding: 20rpx;
		}

		.backAffirm-wrap-des {
			color: $mian-color;
			font-size: 32rpx;
			text-align: center;
			padding: 40rpx;
		}

		.backAffirm-wrap-heard1 {
			width: 200rpx;
			height: 200rpx;
			margin: 0 auto;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.backAffirm-wrap-heard {
			width: 100%;
			height: 150rpx;
			background-image: url('@/static/index/icon_close.png');
			background-size: 100% 100%;
			text-align: right;

			image {
				width: 200rpx;
				height: 200rpx;
				margin: -60rpx -16rpx 0 0;


			}
		}

		height: 800rpx;
		width: 690rpx;
		border-radius: 20rpx;
		background-color: #ffffff;
	}

	.backAffirm-wrap-close {
		width: 60rpx;
		height: 60rpx;
		margin: 50rpx auto auto auto;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.jj {
		width: 100%;
		height: 140vh;
		position: absolute;
		left: 0;
		top: 0;
	}


	// 协议弹框
	.xyPup {
		width: 100%;
		background: #fff;
		border-radius: 30rpx 30rpx 0 0;
		height: 65vh;
	}

	.ty-img {
		width: 32rpx;
		height: 32rpx;
		vertical-align: middle;
		margin-right: 10rpx;
	}

	.getCode {

		color: $mian-color;
		font-size: 28rpx;

	}

	.logon-message1 {
		font-size: 40rpx;
		color: #333;
		position: absolute;
		font-weight: 600;
		top: 35vw;
		left: 5vw;
		right: 5vw;
		padding: 60rpx 0rpx 30rpx 0rpx;
		border-radius: 10rpx;
		margin: 0 auto;
	}

	.logon-message {

		position: absolute;
		// width: 80%;
		// top: 28%;
		top: 59vw;
		// left: 5%;

		// left: 8vw;
		// right: 8vw;
		left: 5vw;
		right: 5vw;
		// width: 76vw;
		// padding: 60rpx 30rpx 30rpx 30rpx;
		padding: 60rpx 0rpx 30rpx 0rpx;
		// height: 32vh;
		// background: #fff;
		border-radius: 10rpx;
		margin: 0 auto;

		.logon-message-tit {
			margin-left: 3vw;
			margin-right: 3vw;
			font-size: 30rpx;
			color: #333;
			padding: 10rpx;
			width: 90%;
			margin: 0 auto;

		}



		.logon-message-phone {
			margin: 0 auto;
			font-size: 0.875rem;

			margin-right: 5vw;
			justify-content: space-between;

			display: flex;
			align-items: center;
			border-bottom: 0.0625rem solid #E9E9E9;

			input {
				// padding-left: 20rpx;
				-webkit-appearance: none !important;
				background-color: transparent !important;
				border: none !important;
			}
		}

	}

	.cpt_mark {
		position: fixed;
		top: 0rpx;
		left: 0rpx;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 99;
	}

	.content {
		display: flex;
		flex-direction: column;
	}

	.logon-message-submit {
		width: 100%;
		border-radius: 100rpx;
		color: #fff;
		font-size: 32rpx;
		line-height: 100rpx;
		text-align: center;
		letter-spacing: 4rpx;
		font-family: PingFang SC, PingFang SC;
		margin-top: 100rpx;
		background: $mian-color;
	}



	input:-webkit-autofill,
	input:-webkit-autofill:hover,
	input:-webkit-autofill:focus,
	input:-webkit-autofill:active {
		-webkit-transition-delay: 99999s;
		-webkit-transition: color 99999s ease-out, background-color 99999s ease-out;
	}
</style>